#!/usr/bin/env python
import numpy as np
import matplotlib.pyplot as plt
import sys
from astropy.table import Table

ptc_f = sys.argv[1]
noise_f = sys.argv[2]
cte_f = sys.argv[3]

ptc_tab = Table.read(ptc_f,format='ipac')
noise_tab = Table.read(noise_f,format='ipac')
cte_tab = Table.read(cte_f,format='ipac')
result = np.zeros((16,9))
wave = ptc_tab['wave'].data
idx = np.where(wave==620)[0]
result[:,0] = ptc_tab['gain'][idx]
result[:,1] = ptc_tab['full'][idx]/1000
result[:,2] = ptc_tab['nlrsp20'][idx]
result[:,3] = ptc_tab['nlrsp10'][idx]
result[:,4] = ptc_tab['nlptc20'][idx]
result[:,5] = ptc_tab['nlptc10'][idx]
result[:,6] = np.array(list(noise_tab[-1].as_void())[1:])
result[:,7] = cte_tab[16:]['cte_serial'].data*100
result[:,8] = cte_tab[16:]['cte_parallel'].data*100
np.savetxt(sys.argv[4],result,fmt='%10.4f')
